package com.sise.cn.task.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 龚秀峰
 * @version 1.0
 * @date 2020/6/8 14:36
 */
@Component
@RabbitListener(queues = "task")
public abstract class AbstractTaskReceiver {

    /**
     * 任务处理的方式，根据不同实现处理不同的任务
     *
     * @param obj 接收的任务对象
     */
    @RabbitHandler
    public void handle(Object obj, Channel channel, Message message) throws IOException {
        task(obj, channel, message);
    }

    /**
     * 子类重写该方法处理消息
     *
     * @param obj 消息的内容
     */
    public abstract void task(Object obj, Channel channel, Message message) throws IOException;
}
